package leetcode.p401;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: trtan
 * @date: 2021-06-21 08:53
 **/
public class BinaryWatch {
    public List<String> readBinaryWatch(int turnedOn) {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < (1 << 10); i++) {
            int cnt = 0;
            int h = 0, m = 0;
            for (int j = 0; j < 10; j++) {
                int x = (i & (1 << j));
                if (x != 0) {
                    cnt++;
                }
                if (j < 6) {
                    m = m * 2 + (x == 0 ? 0 : 1);
                } else {
                    h = h * 2 + (x == 0 ? 0 : 1);
                }
            }
            if(cnt == turnedOn) {
                if (h <= 11 && m <= 59) {
                    if (m < 10) {
                        list.add("" + h + ":0" + m);
                    } else {
                        list.add("" + h + ":" + m);
                    }
                }
            }
        }
        return list;
    }
}
